#-*-coding:utf8-*-
from pymongo import Connection


class MongoDBHandler(object):
    '''
    MongoDB connector handler
    It provides db connector by user getDB method
    '''

    @staticmethod
    def getDB(dbname="ask-government"):
        db = MongoDBHandler.start_connect("localhost", dbname)
        return db

    @staticmethod
    def start_connect(host, dbname):
        connection = Connection(host, 27017)
        db_ = connection[dbname]
        return db_


class MongoDBCollectionHandler(object):
    '''
    Superclass for the CollectionHandler
    It provides basic methods which applies to CollectionHandlers
    '''

    def __init__(self, collection_name=None):
        self.collection_name = collection_name
        self.col_handler = MongoDBHandler.getDB()[self.collection_name]

    def clean_all(self):
        '''
        Drop the collection which it handles
        '''
        print "Dropping collection " + str(self.collection_name)
        self.col_handler.drop()
